/*
* 射击类
* */
export  class Fighter {
    actiontype:string = "";
    actionstart_x:number = 0;
    actionstart_y:number  = 0;
    action_width:number  = 10;
    action_height:number  = 10;
    actioncount:number  = 0;
    actionindex:number  = 0;
    name = "hhh";
    live:number  = 15000;
    livelimit:number  = 20000;
    demage:number  = 10;
    isfire:boolean  = false;
    ammunition:number  = 0;
    ammunitionlimit :number = 0;
    reloadammou:boolean  = false;
    ratewidth:number =50;
    rateheight:number =50;
    delay:number =50;
    ammunitionbak:number =300;
    ammundelayindex:number =20;
    ammundelay:number =20;  //秒
    kills:number =0; //杀敌数
    liveimageframepath:any = require("../images/live/HealthContainer.png");
    liveimagepath:any= require("../images/live/HealthAmber.png");
    livebackimagepath:any = require("../images/live/HealthGreen.png");
    level:number= 1; //Live/(liveImg.Width * livePer); //生命值等级
    severalval:number= 1; //Live % (liveImg.Width * livePer);//当前登记剩余生命值
    livePer:number = 60;

    constructor( actiontype:string,
                 _actionstart_x:number,
                 _actionstart_y:number,
                 _action_width:number,
                 _action_height:number,
                 _actioncount:number,
                 _actionindex:number,
                 _name:string,
                 _live:number,
                 _livelimit:number,
                 _demage:number,
                 _isfire:boolean,
                 _ammunition:number,
                 _ammunitionlimit:number) {
        this.actionstart_x=_actionstart_x;
        this.actionstart_y=_actionstart_y;
        this.action_width=_action_width;
        this.action_height=_action_height;
        this.actioncount=_actioncount;
        this.actionindex=_actionindex;
        this.name=_name;
        this.live=_live;
        this.livelimit=_livelimit;
        this.demage=_demage;
        this.isfire=_isfire;
        this.ammunition=_ammunition;
        this.ammunitionlimit=_ammunitionlimit;
    }

    drawlive(ctxhead:any){
        //信息描述f
        ctxhead.font = 'oblique small-caps bold 11px Arial' ;
        ctxhead.fillStyle='SkyBlue';
        ctxhead.fillText('姓名：' + this.name, 250, 425);
        ctxhead.fillText('生命：' + this.live, 250, 440);
        ctxhead.stroke();
        ctxhead.font = "oblique small-caps bold 16px Arial";
        ctxhead.fillStyle = "yellow";
        let astr = this.ammunition.toString();
        let ammunitionstr = "弹药：" + astr + "/" + this.ammunitionlimit.toString();  //fighter.ammuninfostr;
        ctxhead.fillText(ammunitionstr, 55, 430);
        ctxhead.fillText("备弹:" + this.ammunitionbak, 75, 480);
        ctxhead.stroke();
         ctxhead.font = "oblique small-caps bold 16px Arial";
         ctxhead.fillStyle = "OrangeRed";
         ctxhead.fillText("杀敌：" + this.kills.toString(), 150, 430);
        ctxhead.stroke();

        //弹夹
        var djimage = new Image();
        djimage.src = require("../images/dj.png"); //"images/dj.png";
        ctxhead?.drawImage(djimage, 55,
            440, 20, 40);

        var imgliveimageframe = new Image();
        imgliveimageframe.src =require("../images/live/HealthContainer.png"); //this.liveimageframepath;
        ctxhead.drawImage(imgliveimageframe, 285, 445, 70, 13);
        // ctxhead.drawImage(this.liveimagepath, 0, 0, (70 / this.livelimit) * this.live, 13, 235, 50, (70 / this.livelimit) * this.live, 13);

        this.level = Math.floor(this.live / (70 * this.livePer)); //生命值等级
        this.severalval = this.live % (70 * this.livePer); //当前登记剩余生命值

        if (this.level >= 4) {
            this.liveimagepath = require("../images/live/HealthWhite.png");
            this.livebackimagepath = require("../images/live/HealthBlue.png");
        } else if (this.level == 3) {
            this.liveimagepath = require("../images/live/HealthBlue.png");
            this.livebackimagepath = require("../images/live/HealthPurple.png");
        } else if (this.level == 2) {
            this.liveimagepath = require("../images/live/HealthPurple.png");
            this.livebackimagepath = require("../images/live/HealthGreen.png");
        } else if (this.level == 1) {
            this.liveimagepath = require("../images/live/HealthGreen.png");
            this.livebackimagepath = require("../images/live/HealthAmber.png");
        } else {
            this.liveimagepath = require("../images/live/HealthAmber.png");
            this.livebackimagepath = require("../images/live/HealthContainer.png");
        }

        var imgliveback = new Image();
        imgliveback.src = this.livebackimagepath;

        var imglive = new Image();
        imglive.src = this.liveimagepath;

        if (this.level < 5) {

            ctxhead.drawImage(imgliveback, 0, 0, 128, 13, 285, 445, 70, 13);

            if (this.live > 0) {
                ctxhead.drawImage(imglive, 0, 0, this.severalval / this.livePer, 13, 285, 445, this.severalval / this.livePer, 13);

                //ctxhead.drawImage(this.liveimagepath, 0, 0, this.severalval / this.livePer * this.live, 13, 235, 50, (70 / this.livelimit) * this.live, 13);
            }
        } else {
            ctxhead.drawImage(imgliveback, 0, 0, 128, 13, 285, 445, 70, 13);
            ctxhead.drawImage(imglive, 0, 0, 128, 13, 285, 445, 70, 13);
        }

    }
}